package com.awesome.common.util.ui;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

/**
 * Author: JFangZ
 * Email: janezhang1901@163.com
 * Date: 2020/9/2 12:26
 * Description:NavigationBar 导航栏工具类
 */
public class NavigationBarUtil {
    /**
     * Author: JFangZ
     * Email: janezhang1901@163.com
     * Date:2020/9/2 12:39
     * Description:判断 NavigationBar 是否显示,对全面屏同样生效
     */
    public static boolean navigationBarIsShow(Activity activity) {
        View view = activity.getWindow().getDecorView();
        if (!(view instanceof ViewGroup)) {
            return false;
        }
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            int id = ((ViewGroup) view).getChildAt(i).getId();
            if (id == View.NO_ID) {
                continue;
            }
            String resourceEntryName = activity.getResources().getResourceEntryName(id);
            if (TextUtils.equals("navigationBarBackground", resourceEntryName)) {
                return true;
            }
        }
        return false;
    }

    /**
     * Author: JFangZ
     * Email: janezhang1901@163.com
     * Date:2020/9/2 12:39
     * Description:获取 NavigationBar 高度
     */
    public static int getNavigationBarHeight(Context context) {
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0) {
            return resources.getDimensionPixelSize(resourceId);
        }
        return 0;
    }
}
